package com.alipay.disruptor;

import com.alipay.traditionalbus.EventBus;
import com.lmax.disruptor.dsl.Disruptor;

import java.util.concurrent.CountDownLatch;

/**
 * Created by crazytime on 14-3-1.
 */
public class LongEventDisruptorPublisher implements Runnable {

    private LongEventProducer disruptor;

    private Long counts=1000L * 1000L * 100L;

    private int capacity;

    private Long[] events;

    private CountDownLatch readSignal;

    public LongEventDisruptorPublisher(Long counts, int capacity, LongEventProducer disruptor,CountDownLatch readSignal){
        this.counts=counts;
        this.capacity=capacity;
        this.events=new Long[capacity];
        this.disruptor=disruptor;
        this.readSignal=readSignal;
    }

    @Override
    public void run() {
        long current=0;
        while(current<counts){
            for(int i=0;i<capacity;i++){
                events[i]=new Long(i);
            }
            disruptor.onData(events);
            current=current+capacity;
        }
        readSignal.countDown();
    }


}
